package mx.com.matersys.vacs.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.UserDetails;

public class UserDetailsImpl extends Usuarios implements UserDetails {
	
	public UserDetailsImpl(){
	}
	
	public UserDetailsImpl(Usuarios user) {
		this.setUsername(user.getUsername());
		this.setPassword(user.getPassword());
		this.setCurrentUpdate(user.getCurrentUpdate());
		this.setEnabled(user.isEnabled());
		this.setRoles(user.getRoles());
	}
	
	@Override
	public Collection<GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> listOfAuthorities = new ArrayList<GrantedAuthority>();
		
        /*
        System.out.println("roles:----");
		for (String role : this.getRoles()) {
			System.out.println("role: "+ role);
			listOfAuthorities.add(new GrantedAuthorityImpl(role));
		}
		*/
        listOfAuthorities.add(new GrantedAuthorityImpl("ROLE_ADMIN"));
		
		return listOfAuthorities;
	}

	@Override
	public boolean isAccountNonExpired() {
		return this.isEnabled();
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

}
